#include <string.h>
#include <iostream>
#include <fstream>
#include <string>
using std::cout;
using std::endl;
using std::istream;
using std::ifstream;
using std::string;

void checkStatus(const istream & is){
    cout << "is's goodbit:" << is.good() << endl;
    cout << "is's badbit:" << is.bad() << endl;
    cout << "is's failbit:" << is.fail() << endl;
    cout << "is's eofbit:" << is.eof() << endl;
    cout << endl;
}

void test0(){
    ifstream ifs;
    ifs.open("explicit.cc");
    
    //1.兼容C的方式
    char buff[100] = {0};
    while(ifs.getline(buff,sizeof(buff))){
        cout << buff << endl;
        memset(buff,0,sizeof(buff));
    }

    //将文件输入流对象的状态恢复为goodbit状态
    //仍不能直接再一次地读取内容
    //为什么？
    cout << endl;
    ifs.clear();
    cout << ifs.good() << endl;
    ifs.seekg(0);

    //2.利用<string>提供的getline函数
    //这种方式更常用
    string line;
    while(std::getline(ifs,line)){
        cout << line << endl;
    }

    //关闭文件流
    ifs.close();
}

int main(void){
    test0();
    return 0;
}
